package com.wjw.controller;

import com.wjw.model.Evaluate_grade_table;
import com.wjw.service.EvaluateGradeTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 评定等级表数据库操作:控制层
 */
@Controller
@RequestMapping("/evaluateGrade")
public class EvaluateGradeTableController {
    
    @Autowired
    private EvaluateGradeTableService evaluateGradeTableService;

    @RequestMapping(value = "/findByPage",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findByPage(int page, int limit){
        List<Evaluate_grade_table> byPage = evaluateGradeTableService.findByPage(page, limit);System.out.println(byPage);
        List<Evaluate_grade_table> all =evaluateGradeTableService.findAll();
        Map<String,Object> tableData =new HashMap<String,Object>();
        //这是layui要求返回的json数据格式
        tableData.put("code", 0);
        tableData.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        tableData.put("count", all.size());
        //将分页后的数据返回（每页要显示的数据）
        tableData.put("data", byPage);
        //返回给前端
        return tableData;
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String add(Evaluate_grade_table employee_table_view){
        //System.out.println(employee);
        boolean add = evaluateGradeTableService.add(employee_table_view);
        if(add==true){
            String message="成功";
            return message;
        }else{
            String message="失败";
            return message;
        }
    }

    @RequestMapping(value = "/findAll",method = RequestMethod.POST)
    @ResponseBody
    public List<Evaluate_grade_table> findAll(){
        List<Evaluate_grade_table> all = evaluateGradeTableService.findAll();
        return all;
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String delete(int id){
        boolean add = evaluateGradeTableService.delete(id);
        if(add==true){
            String message="成功";
            return message;
        }else{
            String message="失败";
            return message;
        }
    }

    @RequestMapping(value = "/change",method = RequestMethod.POST,produces="text/html;charset=UTF-8")
    @ResponseBody
    public String change(Evaluate_grade_table employee){
        boolean add = evaluateGradeTableService.change(employee);
        if(add==true){
            String message="成功";
            return message;
        }else{
            String message="失败";
            return message;
        }
    }
}
